package com.cheng.student.controller.servlet;

import com.cheng.student.service.TeacherServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Locale;

//0
@WebServlet(name = "AddTeacherServlet", value = "/super/AddTeacherServlet")
public class AddTeacherServlet
        extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        String name = request.getParameter("name");
        String payrollNumber = request.getParameter("payrollNumber");
        String password = request.getParameter("password");
        //校验
        if (name == null||payrollNumber == null||password == null)
        {
            response.getWriter().write("添加失败");
            return;
        }
        if("".equals(name)||"".equals(payrollNumber)||"".equals(password))
        {
            response.getWriter().write("添加失败");
            return;
        }
        //通过
        TeacherServiceImpl teacherService = new TeacherServiceImpl();
        try
        {
            teacherService.addTeacher(name,payrollNumber,password,"src/main/resources/teacherPictures/setPortrait.png");
        }
        catch (Exception exception)
        {
            response.getWriter().write("添加失败，已存在");
            return;
        }
        response.getWriter().write("添加成功，恭喜你");
        return;
    }
}
